import { Button, Col, DatePicker, Form, Row } from 'antd';
import React from 'react';
import SelectUrl from '../../../components/SelectUrl';
import Actions from './ActionStore/Actions';


const { RangePicker } = DatePicker;
const FormItem = Form.Item;

class QueryOptions extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            confirmDirty: false,
            loadingSelect: false,
            exporting: false,
            datevalue: '',
        }
    }

    handleReset = () => {
        this.props.form.resetFields();
        // console.log(this.state.clear);
        this.child.onexam();

    }
    addDate = (date, days) => {
        var d = new Date(date);
        d.setDate(d.getDate() + days);
        var month = d.getMonth() + 1;
        var day = d.getDate();
        if (month < 10) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        var val = d.getFullYear() + "-" + month + "-" + day;
        return val;
    }
    handleSubmit = (e) => {
        e.preventDefault();
        this.props.form.validateFieldsAndScroll((err, fieldsValue) => {
            if (!err) {
                this.setState({ loadingSelect: true });
                const contractNo = fieldsValue['contractNo'] ? fieldsValue['contractNo'] : '';
                // const contractNo = fieldsValue['contractNo'] ? fieldsValue['contractNo'] : '';
                const gmtCreate = fieldsValue['gmtCreate'];
                const kwValue = fieldsValue['kwvalue'] ? fieldsValue['kwvalue'] : '';
                var kw = kwValue.substring(0, 3)
                console.log(kw)
                var minkwValue = '';
                var maxkwValue = '';
                var eqkwValue = '';
                if (kw == 'gt:') {
                    minkwValue = kwValue.substring(3)
                    console.log(minkwValue)
                } else if (kw == 'lt:') {
                    maxkwValue = kwValue.substring(3)
                } else if (kw == 'eq:') {
                    eqkwValue = kwValue.substring(3)
                }
                //将fieldsValue深拷贝给value
                let values = {
                    'dateDaysMin': minkwValue,
                    'dateDaysMax': maxkwValue,
                    'dateDays': eqkwValue,
                    'contractNo': contractNo,
                    // 'contractNo': contractNo,
                    'gmtCreateMin': gmtCreate != null && gmtCreate != '' ? gmtCreate[0].format('YYYY-MM-DD HH:mm:ss') : "",
                    'gmtCreateMax': gmtCreate != null && gmtCreate != '' ? gmtCreate[1].format('YYYY-MM-DD HH:mm:ss') : "",
                };

                console.log('表单提交的值123==23423======= ', values);

                Actions.searchCondition(values);
                setTimeout(() => {
                    this.setState({ loadingSelect: false })
                }, 1000); //缓冲,防止连击
            }
        });
    };

    //数字类型查询条件
    showNumberOption = (searchColumnItem) => {
        this.refs.NumberOption.showModal(searchColumnItem);
    };
    numberCallback = (searchCondition, viewCondition) => {
        console.log("==========================");
        console.log(searchCondition);
        console.log(viewCondition);

        this.setState({
            datavalue: viewCondition
        });
        this.props.form.setFieldsValue({
            kwvalue: viewCondition,
        });
    };
    render() {
        const { getFieldDecorator } = this.props.form;
        const formItemLayout = {
            labelCol: {
                xs: { span: 24 },
                sm: { span: 8 }
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 14 }
            }
        };
        const tailFormItemLayout = {
            wrapperCol: {
                xs: { span: 4, offset: 5 },
                sm: { span: 4, offset: 5 }
            }
        };
        //一行几个 （总宽度24,）
        const colNumber = 6;
        return (
            <div>
                <div style={{fontSize:'1.2rem',padding:'1em 2.7em 0',backgroundColor: '#fff'}}>合同销售情况报表</div>
                <Form
                    onSubmit={this.handleSubmit}
                    style={{
                        backgroundColor: '#fff',
                        paddingTop: '20px'
                    }}>
                    <Row style={{ textAlign: 'left' }}>
                        <Col span={7}>
                            <FormItem {...formItemLayout} label="合同号">
                                {getFieldDecorator('contractNo', {
                                    initialValue: '',
                                    rules: [{required: true, message: '请输入合同号'}]
                                })(<SelectUrl url={'/base/data/contract/get'} type="get" dicCode="contractNo" dicName="contractNo" />)}
                            </FormItem>
                        </Col>
                        <Col offset={5} span={3}>
                            <FormItem {...tailFormItemLayout}>
                                <Button type="primary" htmlType="submit"
                                    size="large" loading={this.state.loadingSelect}>查询
                                </Button>

                            </FormItem>
                        </Col>
                        {/* <Col span={2} style={{ marginLeft: 15 }}>
                            <Button onClick={this.handleReset} size="large" >
                                <Icon type="retweet" /> 清除
                            </Button>
                        </Col> */}

                    </Row>
                </Form>
            </div>
        );
    }
}

export default Form.create()(QueryOptions);